﻿<?php
// 所有模型类的基类
class Model {
	protected $_db; // 数据库对象
	protected $_sql;
	public function __construct() {
		$this->_db = DB::get_instance();
	}
	// 获取 query 的全部数据
	public function get_all($data=NULL) {
		if (!isset($this->_sql)) {
			throw new Exception("No SQL query!");
		}
		$stmt = $_db->prepare($this->_sql);
		$stmt->execute($data);
		return $stmt->fetchAll();
	}
	// 获取一列数据
	public function get_row($data=NULL) {
		if (!isset($this->_sql)) {
			throw new Exception("No SQL query!");
		}
		$stmt = $_db->prepare($this->_sql);
		$stmt->execute($data);
		return $stmt->fetch();
	}
	protected  function _set_sql($q) {
		$this->_sql = $q;
	}

}